package com.mg.framework.kernel;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.view.MotionEvent;

public abstract class ControllerScreen extends Screen implements Touchable {

	private int moveWidth;
	private int moveHeight;
	private final int moveWH = 120;

	private int okWidth;
	private int okHeight;
	private final int okWH = 60;

	private int cancelWidth;
	private int cancelHeight;
	private final int cancelWH = 50;

	private int menuWidth;
	private int menuHeight;
	private final int menuWH = 30;

	private String[] actorsName;

	private Actor moveController;
	private Actor okController;
	private Actor cancelController;
	private Actor menuController;

	public ControllerScreen(int width, int height) {
		super(width, height);
		this.actorsName = new String[4];
	}

	protected void addMoveController() {
		this.moveWidth = this.moveHeight = moveWH;
		this.moveController = new MoveController(this,
				Bitmap.createScaledBitmap(Assets.moveC, moveWidth, moveHeight,
						true));
		this.addActor("moveController", this.moveController);
		this.actorsName[0] = "moveController";
	}

	protected void addOkController() {
		this.okWidth = this.okHeight = okWH;
		this.okController = new OkController(this, Bitmap.createScaledBitmap(
				Assets.okC, okWidth, okHeight, true));
		this.addActor("okController", this.okController);
		this.actorsName[1] = "okController";
	}

	protected void addCancelController() {
		this.cancelWidth = this.cancelHeight = cancelWH;
		this.cancelController = new CancelController(this,
				Bitmap.createScaledBitmap(Assets.cancelC, cancelWidth,
						cancelHeight, true));
		this.addActor("cancelController", this.cancelController);
		this.actorsName[2] = "cancelController";
	}

	protected void addMenuController() {
		this.menuWidth = this.menuHeight = menuWH;
		this.menuController = new MenuController(this,
				Bitmap.createScaledBitmap(Assets.menuC, menuWidth, menuHeight,
						true));
		this.addActor("menuController", this.menuController);
		this.actorsName[3] = "menuController";
	}

	@Override
	public void onTouchEvent(MotionEvent event) {
		this.dispenseToActors(this.actorsName, event);
	}

	@Override
	public boolean isTouched(MotionEvent event) {
		return true;
	}

	protected void controllerScreenUpdate(Canvas canvas) {
		for (int i = 0; i < 4; i++) {
			if (this.actorsName[i] != null) {
				this.getBaseActor(this.actorsName[i]).screenUpdate(canvas);
			}
		}
	}

	protected void controllerGameUpdate() {
		for (int i = 0; i < 4; i++) {
			if (this.actorsName[i] != null) {
				this.getBaseActor(this.actorsName[i]).gameUpdate();
			}
		}
	}
	
	public void moveNotice(CommandEnum commandState){
		
	}
	
	public void okNotice(CommandEnum commandState){
		
	}
	
	public void cancelNotice(CommandEnum commandState){
		
	}

	public void menuNotice(CommandEnum commandState) {
		
	}
}
